package com.jwdf.uda.ui.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemReplyLikeBinding;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 2016/10/17.
 */
public class ReplyLikeAdapter extends AbsAdapter<PbBean.PbUserSimple> {

    public ReplyLikeAdapter(Context context) {
        super(context);
    }

    @Override
    protected AbsViewHolder onCreateViewHolder(ViewGroup parent, int itemType) {
        return new UserSimpleViewHolder(mInflater.inflate(R.layout.item_reply_like, parent, false));
    }

    private class UserSimpleViewHolder extends AbsViewHolder<PbBean.PbUserSimple> {
        private ItemReplyLikeBinding mItemBinding;

        public UserSimpleViewHolder(View convertView) {
            super(convertView);
            mItemBinding = DataBindingUtil.bind(convertView);
            convertView.setOnClickListener(this);
        }

        @Override
        protected void onBindView(PbBean.PbUserSimple item) {
            if (item == null) return;
            ImageLoader.getInstance().displayImage(item.getAvatar().getUrl(), mItemBinding.ivHeader);
            mItemBinding.tvName.setText(item.getNickname());
            mItemBinding.ivDesigner.setVisibility(View.GONE);
            mItemBinding.setIsDesigner(item.getIsDesigner());
            mItemBinding.tvIntroduction.setVisibility(TextUtils.isEmpty(StringUtils.filterNullAndTrim(item.getIntroduction())) ? View.GONE:View.VISIBLE);
            mItemBinding.tvIntroduction.setText(item.getIntroduction());
        }

        @Override
        public void onClick(View v) {
            UserInfoActivity.start(v.getContext(), item.getUserId(), item.getIsDesigner());
        }
    }
}
